package manager

import (
	"BlazeRider-backend/config"
	"fmt"
	"time"
)

// TrackInfo 存储用户信息的结构体
type TrackInfo struct {
	LiveRoomId string
	UserId     string
	Times      int
	Track      int
	CreateAt   time.Time
	UpdateAt   time.Time
	// 可以添加其他需要的用户信息字段
}

type TrackManager struct {
	storage TrackStorage
}

func NewTrackManager() (*TrackManager, error) {
	var storage TrackStorage
	var err error

	if config.Get().Database.Enabled {
		storage, err = newTrackMySQLStorage()
		if err != nil {
			return nil, fmt.Errorf("failed to init MySQL storage: %v", err)
		}
	} else {
		storage = newTrackMemStorage()
	}

	return &TrackManager{storage: storage}, nil
}

func (um *TrackManager) GetUserTrack(roomId string, userId string, times int) (*TrackInfo, bool) {
	return um.storage.GetUserTrack(roomId, userId, times)
}
